package com.bos.service.impl;

import com.bos.data.model.BosParamModel;
import com.bos.data.repositories.impl.BaseRepository;
import com.bos.mapper.Bos_paramMapper;
import com.bos.service.Bos_paramService;
import com.bos.common.PageData;
import com.google.common.base.Strings;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("bos_paramServiceImpl")
public class Bos_paramServiceImpl extends BaseRepository implements Bos_paramService {
    @Autowired
    Bos_paramMapper paramMapper;

    //1.查询出Bos_param中的值
    @Override
    public PageData findParam(int pageSize, int pageNo, String modelName, String modelAccount) {
        List<BosParamModel> list = paramMapper.findParams();
        String sql = "select * from Bos_param where 1=1";
        Map map = new HashMap();
        if (!Strings.isNullOrEmpty(modelName) && !modelName.trim().isEmpty()) {
            sql += " and typeName like :modelName ";
            map.put("modelName", "%" + modelName + "%");
        }
        if (!Strings.isNullOrEmpty(modelAccount) && !modelAccount.trim().isEmpty()) {
            sql += " and paramValue like :modelAccount ";
            map.put("modelAccount", "%" + modelAccount + "%");
        }
        return this.getPage(sql, map, pageSize, pageNo);
    }

    //2.将模块名称和模块描述插入到数据库表中
    @Override
    public int insertParams(BosParamModel param) {
        return paramMapper.insertParams(param);
    }

    //3.根据paramId来排序，并且查询出paramId的值
    @Override
    public BosParamModel findParamId() {
        return paramMapper.findParamId();
    }

    //4.根据id删除数据
    @Override
    public int deleteById(int id) {
        return paramMapper.deleteById(id);
    }
    //5.根据id修改paramValue的数据
    @Override
    public int updateByParam(BosParamModel paramModel){
        return paramMapper.updateByParam(paramModel);
    }

}
